from PyQt4.QtCore import QCoreApplication
from PyQt4.QtGui import QWidget, QLabel, QPixmap, QFrame
from ..widgets.image_button import ImageButton
from ..data import save_manager
import screen_manager

class MainMenu(QWidget):
	def __init__(self, *args, **kw):
		QWidget.__init__(self, *args, **kw)
		self.setGeometry(0, 0, 1024, 768)

		pic = QLabel(self)
		pic.setGeometry((1024-710)/2, 140, 710, 188)
		path = "resources/logo.png"
		pic.setPixmap(QPixmap(path))

		self.frame = QFrame(self)
		self.frame.setGeometry((1024-800)/2, 600, 800, 100)
		#self.frame.setFrameStyle(QFrame.Panel | QFrame.Raised);

		new_butt = ImageButton("new_game", self.frame, 
			"resources/begin_anew_normal.png",
			"resources/begin_anew_hover.png",
			"resources/begin_anew_active.png",
			"resources/begin_anew_disabled.png"
		)
		new_butt.setGeometry(0, 0, 210, 50)
		new_butt.clicked.connect(
			self.show_new_game
		)

		self.load_butt = ImageButton("load_game", self.frame, 
			"resources/resume_normal.png",
			"resources/resume_hover.png",
			"resources/resume_active.png",
			"resources/resume_disabled.png"
		)
		self.load_butt.setGeometry(400-210/2, 0, 210, 50)

		quit_butt = ImageButton("quit_game", self.frame, 
			"resources/depart_normal.png",
			"resources/depart_hover.png",
			"resources/depart_active.png",
			"resources/depart_disabled.png"
		)
		quit_butt.setGeometry(800-210, 0, 210, 50)
		quit_butt.clicked.connect(
			QCoreApplication.instance().quit
		)

	def show_new_game(self):
		screen_manager.show("new game")
	def show_load_screen(self):
		screen_manager.show("load screen")

	def show(self):
		self.load_butt.clicked.connect(
			self.show_load_screen
		)
		sm = save_manager
		no_saves = (sm.count() <= 0)
		QFrame.show(self)
#
#		if there are no saves, disable the load button
#
		self.load_butt.setDisabled(no_saves)




